# Contributor: Aiden Grossman <agrossman154@yahoo.com>
# Maintainer:
pkgname=gmsh
pkgver=4.12.2
pkgrel=2
pkgdesc="Automatic 3D finite element mesh generator"
url="https://gmsh.info/"
# s390x: opencascade
# armv7, armhf: segfaults
# x86: fails tests
arch="all !x86 !armv7 !armhf !s390x"
license="GPL-2.0-or-later" # license lists several exceptions
makedepends="
	chrpath
	cmake
	fltk-dev
	glu-dev
	gmp-dev
	hdf5-dev
	jpeg-dev
	mesa-dev
	opencascade-dev
	samurai
	"
subpackages="$pkgname-dbg $pkgname-doc gmsh-py:py:noarch"
source="
	https://gmsh.info/src/gmsh-$pkgver-source.tgz
	gmsh-3e841c3943fbb47f29bb582deb298ca33ffe9d25.patch::https://gitlab.onelab.info/gmsh/gmsh/-/commit/3e841c3943fbb47f29bb582deb298ca33ffe9d25.patch
	"
builddir="$srcdir/$pkgname-$pkgver-source"

build() {
	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DRPATH=OFF \
		-DTESTS="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	# Drop redundant /usr/lib from rpath
	chrpath -d "$pkgdir"/usr/bin/gmsh
}

py() {
	depends="$pkgname=$pkgver-r$pkgrel python3"
	amove usr/bin/onelab.py
}

sha512sums="
935148aff89b608f9d671d5fd4f12aed52b5c8ba4453e978d0febcc6934c045f2bba0078b13a64b2cbf4e852b413bbd05873335099ea7a967cc81ef58a7f8367  gmsh-4.12.2-source.tgz
9bb54084d78097b7f27f222e135d3bbeb13263b5cb7a1bb180edfedde5a960ab8db40df7bcb4f3420044727fd25e2e3f1c1f79d890666245cbc0bbbe286f04ee  gmsh-3e841c3943fbb47f29bb582deb298ca33ffe9d25.patch
"
